package com.sinochem.yunlian.ship.base.rpc;

import com.sinochem.yunlian.ship.api.vo.bs.MaterialCategoryVO;
import com.sinochem.yunlian.ship.base.biz.BsMaterialCategoryBiz;
import com.sinochem.yunlian.ship.base.entity.BsMaterialCategory;
import com.sinochem.yunlian.ship.base.enume.BaseMaterialCategoryLeve;
import com.sinochem.yunlian.ship.common.annotation.IgnoreToken;
import com.sinochem.yunlian.ship.common.constant.DisableStatus;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @Descript
 *
 * @Date 2017年12月8日
 */
@RestController
@IgnoreToken
@RequestMapping("api/category")
public class BsMaterialCategoryRest {

	@Resource
	private BsMaterialCategoryBiz bsMaterialCategoryBiz;
	 
	/**
	 * @Descript 根据航线id获取该航线的运载货品
	 */
	@RequestMapping(value = "getCategoryName/{id}", method = RequestMethod.GET)
	public String getBsMaterialCategoryName(@PathVariable("id") Long id) {
		return bsMaterialCategoryBiz.getBsMaterialCategoryName(id);
	}

	/**
	 * @Descript 根据航线id获取该航线的运载货品
	 */
	@RequestMapping(value = "/findMaterialCategoryListByName/{categoryName}", method = RequestMethod.GET)
	public List<MaterialCategoryVO> findMaterialCategoryListByName(@RequestParam("categoryName") String categoryName) {
		List<MaterialCategoryVO> materialCategoryVOList = new ArrayList<MaterialCategoryVO>();
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("disableStatus", DisableStatus.STATUS_ENABLE);
		params.put("level", BaseMaterialCategoryLeve.THREE_LEVEL.getLevel());
		params.put("categoryName",categoryName);
		List<BsMaterialCategory> bsMaterialCategoryList = bsMaterialCategoryBiz.findMaterialCategoryListByMap(params);
		for(BsMaterialCategory bsMaterialCategory: bsMaterialCategoryList){
			MaterialCategoryVO materialCategoryVO = new MaterialCategoryVO();
			materialCategoryVO.setId(bsMaterialCategory.getId());
			materialCategoryVO.setCategoryName(bsMaterialCategory.getCategoryName());
			materialCategoryVO.setLevel(bsMaterialCategory.getLevel());
			materialCategoryVO.setParentId(bsMaterialCategory.getParentId());
			materialCategoryVO.setSeqNum(bsMaterialCategory.getSeqNum());
			materialCategoryVOList.add(materialCategoryVO);
		}
		return materialCategoryVOList;
	}
	
}
